<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="../../../static/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../../../static/js/jquery.js"></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>数据统计</li>
    <li>入库统计</li>
    <li>入库详情</li>
  </ul>
</div>
<div class="rightinfo">
  <form action="" method="post">
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>仓库名称</th>
          <th>采购单编号</th>
          <th>商品数量</th>
          <th>金额</th>
          <th>入库时间</th>
          <th>入库人</th>
          <th>采购单详情</th>
        </tr>
      </thead>
      <tbody id="ckwarehousetr">
        <tr>
          <td>1</td>
          <td>南京21号仓库</td>
          <td>CG201701270001</td>
          <td>5</td>
          <td>￥76,582</td>
          <td>2017-01-25 15:05:05</td>
          <td>马云</td>
          <td>
          	<a href="/storage/inventory/inventoryView" class="tablelink">查看详情</a>
          </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <div class="message">共<i class="blue" id="totalCount">1256</i>条记录，当前显示第&nbsp;<i class="blue" id="pageNum">2&nbsp;</i>页
      </div>
      <ul class="paginList" id="page">
        <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>
        <li class="paginItem"><a href="javascript:;">1</a></li>
        <!--                <li class="paginItem current"><a href="javascript:;">2</a></li>-->
        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

    $(function () {
      var id = getParameter("id");
      queryCkWarehouse(id);
    })

    function queryCkWarehouse(id, pageNum) {
      $.ajax({
        url: "/stock/rkwarehouse",
        method: "post",
        dataType: "json",
        data: {id: id, pageNum: pageNum},
        success: function (data) {
          console.log(data);
          var str = '';
          var da = data.data.data;
          for (var i = 0; i < da.length; i++) {
            var total = 0;
            for (var j = 0; j < da[i].purchases.length; j++) {
              total += da[i].purchases[j].totalMoney;
            }
            str += `<tr>
                    <td>${i + ((data.data.pageNum - 1) * data.data.pageSize) + 1}</td>
                    <td>${da[i].cname}</td>
                    <td>${da[i].rkIndent}</td>
                    <td>${da[i].purchases[0].cdetails.length}</td>
                    <td>￥${total}</td>
                    <td>${da[i].rkDate}</td>
                    <td>${da[i].user.uname}</td>
                    <td>
                        <a href="/storage/inventory/inventoryView?purchaseid=${da[i].purchases[0].purchaseId}" class="tablelink">查看详情</a>
                    </td>
                    </tr>`;
          }
          $("#ckwarehousetr").html(str);

          $("#totalCount").html(data.data.totalCount);
          $("#pageNum").html(data.data.pageNum);
          var begin = data.data.pageNum - 5;
          var end = data.data.pageNum + 4;
          if (begin < 1) {
            begin = 1;
            if (data.data.totalPage < 10) {
              end = data.data.totalPage;
            } else {
              end = 10;
            }
          }
          if (end > data.data.totalPage) {
            end = data.data.totalPage;
            if (begin < 0) {
              begin = 1;
            }
          }
          var page = '';
          page += '<li class="paginItem" id="up"><a onclick="queryCkWarehouse(' + id + ',' + (data.data.pageNum - 1) + ')"><span class="pagepre"></span></a></li>\n';
          for (var i = begin; i <= end; i++) {
            if (i == data.data.pageNum) {
              page += '<li class="paginItem current"><a onclick="queryCkWarehouse(' + id + ',' + i + ')">' + i + '</a></li>';
            } else {
              page += '<li class="paginItem"><a onclick="queryCkWarehouse(' + id + ',' + i + ')">' + i + '</a></li>';
            }
          }
          page += '<li class="paginItem" id="down"><a onclick="queryCkWarehouse(' + id + ',' + (data.data.pageNum + 1) + ')"><span class="pagenxt"></span></a></li>';
          $("#page").html(page);

          if (data.data.pageNum == 1) {
            // $("#up").removeAttr("onclick");
            $("#up").attr("disabled", true).css("pointer-events", "none")
          }
          if (data.data.pageNum == data.data.totalPage) {
            // $("#down").removeAttr("onclick");
            $("#down").attr("disabled", true).css("pointer-events", "none")
          }
        },
        error: function () {
          alert("查询仓库详情失败!");
        }
      })
    }

    function getParameter(name) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      var r = location.search.substr(1).match(reg);
      if (r != null) {
        return (r[2]);
      }
      return null;
    }
</script>
</body>
</html>
